package com.parenting.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.parenting.entities.EvaluationDO;
import com.parenting.mapper.EvaluationMapper;
import com.parenting.model.IMPage;
import com.parenting.request.ShopEvaluateListRequest;
import com.parenting.response.EvaluationListResponse;
import com.parenting.response.NoReplyResponse;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.parenting.service.EvaluationService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 店铺评价 服务实现类
 * </p>
 *
 * @author 烟台业达-王世玺
 * @since 2021-09-27
 */
@Service
public class EvaluationServiceImpl extends ServiceImpl<EvaluationMapper, EvaluationDO> implements EvaluationService {



    @Override
    public IMPage<EvaluationListResponse> getEvaluationListResponse(ShopEvaluateListRequest request, String shopId) {
        IPage<EvaluationDO> evaluationDOIPage = baseMapper.selectPage(request.getPage(),
                new LambdaQueryWrapper<EvaluationDO>().eq(EvaluationDO::getShopId, shopId));
        IMPage<EvaluationListResponse> page=new IMPage<>();
        page.setSize(evaluationDOIPage.getSize());
        page.setCurrent(evaluationDOIPage.getCurrent());
        page.setTotal(evaluationDOIPage.getTotal());
        if (evaluationDOIPage.getTotal()>0){
            List<EvaluationListResponse> list=new ArrayList<>();
            for (EvaluationDO e:evaluationDOIPage.getRecords()) {
                EvaluationListResponse evaluationListResponse = BeanUtil.copyProperties(e, EvaluationListResponse.class);
                List<EvaluationListResponse> replyResponseList = baseMapper.getReplyResponseList(e.getEvaluationId());
                evaluationListResponse.setReplyResponseList(replyResponseList);
                list.add(evaluationListResponse);
            }
            page.setRecords(list);
        }
        return page;
    }

    @Override
    public IMPage<NoReplyResponse> getNoReplyResponseList(IPage<NoReplyResponse> page,String shopId) {
        IPage<NoReplyResponse> noReplyResponseList = baseMapper.getNoReplyResponseList(page, shopId);
        IMPage<NoReplyResponse> imPage=new IMPage<>();
        imPage.setRecords(noReplyResponseList.getRecords());
        imPage.setTotal(noReplyResponseList.getTotal());
        imPage.setCurrent(noReplyResponseList.getCurrent());
        imPage.setSize(noReplyResponseList.getSize());
        return imPage;
    }


}
